﻿using System;
using System.Linq;
using WorkLogger.Client.DataAccess.Model;

namespace WorkLogger.Client {
	public class WorkTimeCalculator {
		public TimeSpan GetWorkedTime(WorkDay workDay) {
			TimeSpan workedTime = workDay.EndWork.TimeOfDay - workDay.StartWork.TimeOfDay;
			return workedTime - GetLunchTime(workDay);
		}

		public TimeSpan GetLunchTime(WorkDay workDay) {
			var time = new TimeSpan();
			if (workDay.LunchTimes == null)
				return new TimeSpan(0, 0, 0);
			return workDay.LunchTimes.Aggregate(time,
			                                    (current, lunchTime) => current + (lunchTime.EndLunch - lunchTime.StartLunch));
		}
	}
}